home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / interp11.zip / INTERP.H < prev    next >
Text File  |  1991-09-24  |  2KB  |  62 lines

  1. /*
  2.  *
  3.  * INTERP.H  - the result codes/prototype for the Expression Interpreter
  4.  *
  5.  * Written September, 1991 by Jonathan Guthrie and placed in the public domain
  6.  *
  7.  */
  8.  
  9. /*
  10.  *
  11.  * eval() evaluates a arithmetic expression passed to it one character
  12.  * at a time by input_function().  It continues the evaluation until it
  13.  * doesn't recognize something, then it stops, checks to see if the
  14.  * parenthesis match, and returns the result.  Result codes other than
  15.  * EV_RES_OK (which signals success,) EV_BADPAREN (which signals mis-
  16.  * matched parenthesis,) EV_OVERFLOW (which signals overflow on
  17.  * multiplication, division, or raise-to-a-power,) or EV_DIV0 (which
  18.  * signals attempted division by zero) indicate internal problems with
  19.  * the evaluator.
  20.  *
  21.  * The result is returned in answer.  input_function is a pointer to
  22.  * a function that returns the next character in the string to be
  23.  * evaluated.  ("Ungetting" is handled by the evaluator, so it isn't
  24.  * necessary that the "input function" do it.)  See the "debug" code
  25.  * in the source for a sample input_function().
  26.  *
  27.  */
  28.  
  29. int     eval(double *answer, int (*input_function)(void));
  30.  
  31. /*
  32.  *
  33.  * These are the result codes used by the interpreter
  34.  *
  35.  */
  36.  
  37. #define EV_RES_OK   0
  38. #define EV_BADTOK   1
  39. #define EV_BADNUM   2
  40. #define EV_BADVAL   3
  41. #define EV_BADPOW   4
  42. #define EV_BADFACT  5
  43. #define EV_BADEXP   6
  44. #define EV_BADPAREN 7
  45. #define EV_OVERFLOW 8
  46. #define EV_DIV0     9
  47.  
  48.  
  49. char    *EV_results[10] =
  50. {
  51.     "",
  52.     "A bad token was found",
  53.     "Internal error in getnumber()",
  54.     "Internal error in value()",
  55.     "Internal error in power()",
  56.     "Internal error in factor()",
  57.     "Internal error in expression()",
  58.     "Missing closing parenthesis",
  59.     "Overflow in expression",
  60.     "Division by zero error"
  61. };
  62.